package com.ithinks.flow.common.utils.protocol.socket.aio.client;

import java.util.Scanner;

/**
 * @Description
 * @ClassName AioClient
 * @Author MR.LI
 * @date 2020.12.07 18:03
 */
public class AioClient {

    /**io处理器*/
    private static AioHandler aioHandler;

    public static void start(){
        if(aioHandler !=null)
            return;
        aioHandler = new AioHandler("127.0.0.1",8889);
        new Thread(aioHandler,"client").start();
    }

    //向服务器发送消息
    public static boolean sendMsg(String msg){
        if(msg.equals("q")) return false;
        aioHandler.sendMessage(msg);
        return true;
    }

    public static void main(String[] args){
        AioClient.start();
        System.out.println("请输入请求消息：...");
        Scanner scanner = new Scanner(System.in);
        while(AioClient.sendMsg(scanner.next()));
    }

}
